/*
 * BSM6.0
 *
 * Copyright 2012-2013 (C) SINODATA CO., LTD. All Rights Reserved.
 */
package com.sinodata.bsm.center.web.action.resource;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;

import com.sinodata.bsm.center.bean.QueryDimensionBean;
import com.sinodata.bsm.center.service.resource.ResViewService;
import com.sinodata.bsm.center.util.web.Struts2Utils;
import com.sinodata.bsm.center.web.action.BaseAction;
import com.sinodata.bsm.common.vo.Res;
import com.sinodata.bsm.common.vo.ResView;
import com.sinodata.bsm.common.vo.ResViewRel;

/**
 * <p>
 * Description: 
 * </p>
 *
 * @author wangyazhou
 * @version 1.0

 * <p>
 * History: 
 *
 * Date                     Author         Version     Description
 * ---------------------------------------------------------------------------------
 * Jul 2, 2012 9:25:00 PM          wangyazhou        1.0         To create
 * </p>
 *
 * @since 
 * @see     
 */
public class MyViewFrameAction extends BaseAction<Res> {

    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    @Autowired
    private ResViewService resViewService;

    /**
     * 
     * 进入默认页面
     */
    @Override
    public String execute() throws Exception {
        return SUCCESS;
    }

    @SuppressWarnings({ "unchecked", "rawtypes" })
    public String initView() throws Exception {

        List results = new ArrayList();
        ResView[] views = resViewService.findAll();
        results.add(views);
        ///////////////////////////////////////
        ResView lastView = (ResView) request.getSession().getAttribute("lastView");
        Map<Long, Long> initResMap = new HashMap<Long, Long>();

        for (ResView view : views) {
            List<ResViewRel> relList = resViewService.getResViewRelByViewId(view.getId());
            if (relList != null && relList.size() > 0) {
                initResMap.put(view.getId(), relList.get(0).getResId());
            }
        }

        request.getSession().setAttribute("lastView", lastView);
        results.add(lastView);

        ////////////////////////////////////////
        String lastViewMenu = (String) request.getSession().getAttribute("lastViewMenu");
        if (lastViewMenu == null) {
            lastViewMenu = "real_perf";
            request.getSession().setAttribute("lastViewMenu", lastViewMenu);
        }
        results.add(lastViewMenu);
        /////////////////////////
        results.add(initResMap);

        //////////////////////
        Struts2Utils.renderJson(results);
        return null;
    }

    /**
     * 保存最后一次二级菜单
     * @return
     * @throws Exception
     */
    public String saveCurrentMenu() throws Exception {
        String menuId = request.getParameter("menuId");
        String type = request.getParameter("type");
        if (type.equals("2")) {
            request.getSession().setAttribute("lastViewMenu", menuId);
        } else {
            request.getSession().setAttribute("lastResTypeMenu", menuId);
        }
        return null;
    }

    @Override
    public Res getModel() {
        return null;
    }

    @Override
    public String list() throws Exception {
        return null;
    }

    @Override
    public String input() throws Exception {
        return null;
    }

    @Override
    public String save() throws Exception {
        return null;
    }

    @Override
    public String delete() throws Exception {
        return null;
    }

    @Override
    protected void prepareModel() throws Exception {

    }

}
